package VisaoControleAcademico;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.ParseException;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.border.TitledBorder;
import javax.swing.table.DefaultTableModel;
import javax.swing.text.MaskFormatter;

import ControleAcamico.ControlePrincipal;
import ControleDiversas.PesquisarCursoAddMatricular;

public class MatriculaView extends JFrame {
	public static JLabel labCursoMatri, labDataMatri, labTurmMatri,
			labConteuMatri;
	public static JFormattedTextField txtDataMatri;
	public static JComboBox jcomTurmaMatri, jcomCursoMatri;
	public static JButton botAddAlunoMatri, botCadastroMatri, botCancelarMatri,apagarNomeAluno;
	public static JTable tabelaMatri;
	public static JScrollPane scrollMatriTab, scrollMatriArea;
	public static JTextArea areaMatriCont;
	private JScrollPane textArear;
	public static JPanel panlPrincMatri, panlMatri1, panlMatri2;
	private ControlePrincipal controle;

	public MatriculaView(ControlePrincipal controle) {
		this.controle = controle;
		init();
		setup();
		adicionar();
		sair();
		executar();
		

	}

	private void sair() {
		botCancelarMatri.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int grande = JOptionPane.showConfirmDialog(null,
						"Tem serteza que Deseja  Sair?", "Confirme",
						JOptionPane.OK_CANCEL_OPTION);

				if (grande == JOptionPane.OK_OPTION) {
					hide();
				}

			}
		});
		
	}

	private void adicionar() {
		panlPrincMatri.add(panlMatri2);
		panlMatri2.add(labTurmMatri);
		panlMatri2.add(jcomTurmaMatri);
		panlMatri2.add(labCursoMatri);
		panlMatri2.add(jcomCursoMatri);
		panlMatri2.add(labDataMatri);
		panlMatri2.add(txtDataMatri);
		panlPrincMatri.add(labConteuMatri);
		panlPrincMatri.add(textArear);

		panlPrincMatri.add(panlMatri1);
		panlMatri1.add(scrollMatriTab);
		panlMatri1.add(botAddAlunoMatri);
		panlMatri1.add(apagarNomeAluno);
		panlPrincMatri.add(botCadastroMatri);
		panlPrincMatri.add(botCancelarMatri);
		add(panlPrincMatri);

	}

	private void setup() {
		panlPrincMatri.setLayout(new FlowLayout(FlowLayout.CENTER));
		panlMatri1.setLayout(new FlowLayout(FlowLayout.CENTER));
		panlMatri2.setLayout(new GridLayout(6, 2, 0, 0));

	}

	private void init() {
		panlPrincMatri = new JPanel();
		panlPrincMatri.setSize(300, 200);

		panlMatri1 = new JPanel();
		panlMatri1.setPreferredSize(new Dimension(530, 190));
		panlMatri1.setBorder(BorderFactory.createTitledBorder(null, "Alunos",
				TitledBorder.CENTER, TitledBorder.DEFAULT_JUSTIFICATION));
		textoArea();
		tabelaMatri = new JTable();
		scrollMatriTab = new JScrollPane();
		tabelaMatri.setModel(new DefaultTableModel(new Object[][] {},
				new String[] {"Nome","cpf"}));
		scrollMatriTab.setPreferredSize(new Dimension(520, 125));
		scrollMatriTab.setViewportView(tabelaMatri);

		botAddAlunoMatri = new JButton("Selecionar Alunos");
		botAddAlunoMatri.addActionListener(controle);
		apagarNomeAluno = new JButton("Excluir Aluno");
		apagarNomeAluno.addActionListener(controle);

		panlMatri2 = new JPanel();
		panlMatri2.setPreferredSize(new Dimension(200, 130));
		labTurmMatri = new JLabel("Turma");
		jcomTurmaMatri = new JComboBox();
		jcomTurmaMatri.addActionListener(controle);
		labCursoMatri = new JLabel("Curso");
		jcomCursoMatri = new JComboBox();
		jcomCursoMatri.addActionListener(controle);

		labDataMatri = new JLabel("Data");
		try {
			txtDataMatri = new JFormattedTextField(new MaskFormatter(
					"##/##/####"));
		} catch (ParseException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		labConteuMatri = new JLabel("Conteudo:");
		botCadastroMatri = new JButton("Cadastrar");///botal principal
		botCadastroMatri.addActionListener(controle);
		botCancelarMatri = new JButton("Cancelar");
		
		PesquisarCursoAddMatricular.addMatriculaJSC();
	}

	private void textoArea() {
		textArear = new JScrollPane();
		areaMatriCont = new JTextArea();
		areaMatriCont.setEditable(false);
		areaMatriCont.setBackground(panlPrincMatri.getBackground());
		textArear.setPreferredSize(new Dimension(250, 100));
		textArear.setViewportView(areaMatriCont);
		
	}

	private void executar() {
		setTitle("Projeto Controle Academico");
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setSize(550, 400);
		setResizable(false);
		centralizarComponente();
	}
	public void centralizarComponente() {  
        Dimension ds = Toolkit.getDefaultToolkit().getScreenSize();  
        Dimension dw = getSize();  
        setLocation((ds.width - dw.width) / 1, (ds.height - dw.height) / 2);  
    } 
	public void mostrarMatricula() {
		setVisible(true);	
	}

	public static void removeAluno() {
		if (tabelaMatri.getSelectedRow() > -1) {
			PainelListaAluno.dtm.removeRow(tabelaMatri.getSelectedRow());
			PainelListaAluno.d--;
		}
		
	}


	
	}


